<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./js/vue.js"></script>
    <style>
        #app{
            border:2px solid black;
            padding: 10px;
            margin-bottom: 400px;
        }
        .child{
            margin: 20px;
            padding:10px;
            background-color: burlywood;
        }
    </style>
</head>
<body>
    <div id="app">
        <h3>父组件范围</h3>
        <p>info:{{ info }}</p>
        <input type="button" value="获取子组件数据" @click="getInfo()">
        <!-- <child-one v-on:send=" setInfo " @send-msg="printMsg"></child-one> -->
        <child-one v-on:send="setInfo" @send-msg="printMsg"></child-one>
    </div>

    <template id="ChildOne">
        <div class="child">
            <h3>子组件</h3>
            <p>info:{{ info }}</p>
            <input type="button" value="发送数据" @click="sendInfo()">
            <input type="text" v-model="info">

            <input type="button" value="发送数据$emit" @click="sendInfo2()">
            <hr>
            <input type="button" value="调用sendMsg自定义事件" @click=" $emit('send-msg','sendMsg携带的参数') ">
        </div>
    </template>
</body>
<script>
    Vue.component("ChildOne",{
        template:"#ChildOne",
        data(){
            return{
                info:"子组件变量"
            }
        },
        methods: {
            sendInfo(){
                // this.info
                this.$parent.setInfo(this.info)
            },
            sendInfo2(){
                this.$emit("send",this.info,1234,[1,2,3],{a:123})
            }
        },
        mounted() {
            // this.sendInfo();
            console.log(this)
        },
    })
    new Vue({
        el:"#app",
        data:{
            info:""
        },
        methods: {
            getInfo(){
                console.info(this.$children)
                this.info = this.$children[0].info
            },
            setInfo(arg,arg1,arg2,arg3){
                this.info = arg;
                console.log(arg,arg1,arg2,arg3)
            },
            printMsg(arg,arg1,arg2,arg3){
                console.log("printMsg方法");
                console.log(arg,arg1,arg2,arg3)
            }
        },
    })
</script>
</html>